#include #include using namespace std; template class my_pair{ public: A first; B second; my_pair(A x, B y):first(x), second(y){} void print(); }; template void swapk(S &a, S &b){ S t = a; a = b; b = t; } template my_pair make_a_pair(S &a, T &b){ return my_pair(a,b); } void main(){ int x=3, y=42; double p = 3.14159, e = 2.718; string s1 = "s1", s2 = "s2"; swapk(x,y); cout << "after swap x y " << x << " " << y << endl; swapk(p,e); cout << "after swap p e " << p << " " << e << endl; swapk(s1,s2); cout << "after swap s1 s2 " << s1 << " " << s2 << endl; //swapk(s1, p); not allowed my_pair pa = make_a_pair(s1, p); pa.print(); } // show template scope resolution for method // definition outside class template void my_pair::print(){ cout << first << " " << second << endl; }